# -*- coding:utf-8 -*-
# session的使用
import requests


# 1、向登录页发起请求，并且登陆
login_url = "https://passport.17k.com/ck/user/login"   # 登陆页的请求
headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"
}


post_data = {
    "loginName": 15096962415,
    "password": "123456789abc"
}

#  session的使用方法
session = requests.session()      # 创建session对象
session.headers = headers        # 添加请求头
resp = session.post(login_url, data=post_data)
print(resp.text)


# 2、向子页面发送请求的时候，会自动携带登陆之后的cookie
response = session.get("https://www.17k.com/all/book/2_21_0_1_1_0_0_0_1.html")
print(response.text)

